package com.sgb.member.view_model;


import com.sgb.member.di.repository.MemberRepertory;
import com.sgb.member.ui.activity.ChooseMemberTypeActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.view.selection.CommonPopEntity;

import java.util.List;

/**
 * Time:2021/4/30
 * AUTHOR:F_Q
 * Description:
 */
public class ChooseMemberTypeModel extends BaseViewModel {

    ChooseMemberTypeActivity activity;
    MemberRepertory repertory;

    public ChooseMemberTypeModel(ChooseMemberTypeActivity activity, MemberRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    private void showOrHideDialog(boolean aBoolean) {
        if (aBoolean) {
            if (!DialogHelper.isShowing() && activity != null) {
                DialogHelper.showProgressDialog(activity, "数据获取中...");
            }
        } else {
            DialogHelper.dismissProgressDialog();
        }
    }

    // 会员类型
    public void getMemberTypeList(String ascription) {
        showOrHideDialog(true);
        // 0 供方 1需方
        repertory.getApi().getMemberTypeList(ascription).enqueue(new ICallBack<BaseEntity<List<CommonPopEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CommonPopEntity>> data) {
                if (data.getData() != null && data.getData() != null && data.getData().size() > 0) {
                    data.getData().add(0, new CommonPopEntity("", "全部"));
                      activity.setMemberTypes(data.getData());
                }
            }
        });
    }



    //服务类型
    public void getServiceTypeList() {
        showOrHideDialog(true);
        repertory.getApi().getServiceClass().enqueue(new ICallBack<BaseEntity<List<CommonPopEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CommonPopEntity>> data) {
                if (data.getData() != null && data.getData() != null && data.getData().size() > 0) {
                    activity.setMemberTypes(data.getData());
                }
            }
        });
    }

    //经营类型
    public void getManagementTypesList() {
        showOrHideDialog(true);
        repertory.getApi().getServiceTypeList().enqueue(new ICallBack<BaseEntity<List<CommonPopEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CommonPopEntity>> data) {
                if (data.getData() != null && data.getData() != null && data.getData().size() > 0) {
                    activity.setMemberTypes(data.getData());
                }
            }
        });
    }
}
